package com.orange.notificationsummary.loader;

import java.util.Collections;
import java.util.List;

import android.graphics.drawable.Drawable;

import com.orange.homescreen.pil.NotificationSummaryInterface;
import com.orange.homescreen.pil.PILInterfaceManager;
import com.orange.notificationsummary.EventTypeAndCount;
import com.orange.notificationsummary.R;
import com.orange.notificationsummary.SummaryActivity;
import com.orange.notificationsummary.event.pil.defaultimpl.BaseEvent;
import com.orange.notificationsummary.utils.LogHelper;

public class UnreadMsgLoader extends BasicLoader {
	private static final String	TAG	= "UnreadMsgLoader";

	private SummaryActivity		mHostActivity;
	private List<BaseEvent>		mEventList;

	public UnreadMsgLoader(SummaryActivity hostActivity) {
		super("UnreadMsgLoader", LoaderController.UNREADMSG_LOADER);
		this.mHostActivity = hostActivity;
	}

	@Override
	protected void loadData() {
		NotificationSummaryInterface mInterface = (NotificationSummaryInterface) PILInterfaceManager
				.getInterface(NotificationSummaryInterface.class);

		this.mEventList = mInterface.getAllUnreadMessageEvent(mHostActivity);
	}

	@Override
	protected void showData() {
		LogHelper.i(TAG, "showData. ");
		this.mHostActivity.setEventData(mEventList,
				this.getEventTypeAndCount(), this.getLoaderType());
	}

	@Override
	protected EventTypeAndCount getEventTypeAndCount() {
		Drawable msgIcon = mHostActivity.getResources().getDrawable(
				R.drawable.icon_message_24);
		int event_count = 0;
		long event_lasttime = 0;

		if (mEventList != null && !mEventList.isEmpty()) {
			Collections.sort(mEventList);
			event_count = mEventList.size();
			event_lasttime = mEventList.get(0).event_date;
		}

		EventTypeAndCount evnet = new EventTypeAndCount(event_lasttime,
				msgIcon, event_count, mHostActivity);
		return evnet;
		/*
		 * // TODO Auto-generated method stub int event_count = 0; long
		 * event_lasttime = 0; if (mEventList != null) { event_count =
		 * mEventList.size(); }
		 * 
		 * if (event_count > 0) { if (mEventList != null)
		 * Collections.sort(mEventList);
		 * 
		 * event_lasttime = mEventList.get(0).event_date; }
		 * 
		 * EventTypeAndCount evnet = new EventTypeAndCount(event_lasttime,
		 * mHostActivity
		 * .getResources().getDrawable(R.drawable.icon_message_24), event_count,
		 * mHostActivity); return evnet;
		 */}
}